﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Specialized;

namespace TIMSComponents
{
    [ToolboxItem(false)]
    public class BaseControl : System.Windows.Forms.UserControl    
    {

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // CBase
            // 
            this.Name = "BaseControl";
            this.Size = new System.Drawing.Size(150, 21);       
            this.ResumeLayout(false);            

        }


        internal DataAccessLayer data = new DataAccessLayer();

        public StringDictionary Result=new StringDictionary();

        public delegate void fieldListDelegate(string[] fieldList);
        public delegate void SqlCommandTextDelegate(string sqlCommandText);
        public delegate void SqlParamsDelegate(string sqlParams);
        public delegate void ReturnedFieldDelegate(string[] returnedField);
        public delegate void AllowRefreshDelegate(bool Refresh);
        public delegate void ChoiserTypeDelegate(ChoiserType ChoiserTypeA);

        

        public event fieldListDelegate OnfieldListChanged;
        public event SqlCommandTextDelegate OnsqlCommandTextChanged;
        public event SqlParamsDelegate OnsqlParamsChanged;
        public event ReturnedFieldDelegate OnreturnedField;
        public event AllowRefreshDelegate OnallowRefreshChanged;
        public event ChoiserTypeDelegate OnChoiserTypeChanged;

        //Added by andro.  17/09/2008 
        public delegate void ConnectionStringDelegate(string Value);
        public event ConnectionStringDelegate ConnectionStringChanged;

        //Added by andro.  17/09/2008 
        public delegate void IdentityValueDelegate(object Value);
        public event IdentityValueDelegate OnIdentityValueChanged;

        //Added by Andro 2/10/2008
        private System.Windows.Forms.Form _form;
        public System.Windows.Forms.Form frmDic
        {
            get
            {
                return _form;
            }
            set
            {
                _form = value;
            }
        }


        //Added by andro.  17/09/2008 
        private string _IdentityFild;
        [Category("(TIMS)Data")]
        public string IdentityFild
        {
            get
            {
                return _IdentityFild;
            }
            set
            {
                _IdentityFild = value;
            }
        }

        //Added by andro.  17/09/2008 
        private object _IdentityValue=DBNull.Value;
        [Category("(TIMS)Data")]
        public object IdentityValue
        {
            get
            {
                return _IdentityValue;
            }
            set
            {
                if (_IdentityValue == value)
                {
                    return;
                }
                _IdentityValue = value;
                if(OnIdentityValueChanged!=null){
                    OnIdentityValueChanged(value);
                }
            }
        }


        private String _ConnectionString;
        [Category("(TIMS)Data")]
        public String ConnectionString
        {
            get { return _ConnectionString; }
            set
            {
                _ConnectionString = value;
                if (ConnectionStringChanged != null )
                {
                    ConnectionStringChanged(value);
                }
            }
        }

        private string _SQLcommandText="fn_GetCity";
        [Category("(TIMS)Data"), Description("Gets or sets the function or stored procedure's name to execute at the data source")]
        public string SQLcommandText
        {
            get
            {
                return _SQLcommandText;
            }
            set
            {
                if (_SQLcommandText != value)
                {
                    _SQLcommandText = value;
                    if (OnsqlCommandTextChanged!=null)
                    {
                        OnsqlCommandTextChanged(value);
                    }
                }
            }
        }

        private MyCommandType _SQLcommandType = MyCommandType.SqlFunction;
        [Category("(TIMS)Data"), DefaultValue(MyCommandType.SqlFunction)]
        public MyCommandType SQLcommandType
        {
            get
            {
                return _SQLcommandType;
            }
            set
            {
                _SQLcommandType = value;
            }
        }

        private string _SqlParams="1,2";
        [Category("(TIMS)Data"), Description("Parameters for SQL function or stored procedure")]
        public string SqlParams
        {
            get
            {
                return _SqlParams;
            }
            set
            {
                _SqlParams = value;
                if (OnsqlParamsChanged != null)
                {
                    OnsqlParamsChanged(value);
                }
            }
        }

        private string[] _FieldList = new string[] {"CodeID", "hName"};
        [Category("(TIMS)Data"), Description("Names of fields(That fields we need FROM MSSQL). Between names of fields will be separated with ',' symbol ")]
        public string[] FieldList
        {
            get
            {
                return _FieldList;

            }
            set
            {
                _FieldList = value;
                if (OnfieldListChanged != null)
                {
                    OnfieldListChanged(value);
                }
            }
        }

        private string _FieldKeyNN="CodeID";
        [Category("(TIMS)Data"), Description("Field name which we neet to search by Number)")]
        public string FieldKeyNN
        {
            get
            {
                return _FieldKeyNN;
            }
            set
            {
                if (_FieldKeyNN != value)
                {
                    _FieldKeyNN = value;
                }


            }
        }
        
        private string _FieldKeyNS="hName";
        [Category("(TIMS)Data"), Description("Field name which we neet to search by text expression)")]
        public string FieldKeyNS
        {
            get
            {
                return _FieldKeyNS;
            }
            set
            {

                if (_FieldKeyNS != value)
                {
                    _FieldKeyNS = value;
                    //fieldKeyNSChanged(_FieldKeyNS);
                }
            }
        }

        private string[] _ReturnedField = new string[] {"CodeID","hName"};
        [Category("(TIMS)Data"), Description("")]
        public string[] ReturnedField
        {
            get
            {
                return _ReturnedField;
            }
            set
            {
                if (_ReturnedField != value)
                {
                    _ReturnedField = value;
                    if (OnreturnedField != null)
                    {
                        OnreturnedField(value);
                    }
                }
            }
        }
        

        private ChoiserType _ChoiserType = new  ChoiserType();
        [DefaultValue(ChoiserType.asChoiser), Category("(TIMS) Behavior"), Description("Control type")]
        public ChoiserType ChoiserType
        {
            get{
                return _ChoiserType;
            }
            set{
                _ChoiserType=value;
                if (OnChoiserTypeChanged != null)
                {
                    OnChoiserTypeChanged(value);
                }
            }
        }

        private bool _AllowRefresh;
        [Category("(TIMS) Behavior"), Description("Allways update data from DataSource on the starting search")]
        public bool AllowRefresh
        {
            get
            {                
                return _AllowRefresh;
            }
            set
            {
                if (_AllowRefresh != value)
                {
                    _AllowRefresh = value;
                    if (OnallowRefreshChanged!=null)
                    {
                        OnallowRefreshChanged(value);
                    }
                }                
            }
        }

        private bool _AutoStart;
        [Category("(TIMS) Behavior"), Description("Get data from DataSource on the form load")]
        public bool AutoStart
        {
            get
            {
                return _AutoStart;

            }
            set
            {
                _AutoStart = value;
            }
        }

        private int[] _CollumsWidth;
        [Category("(TIMS) Grid"), Description("Collums width")]
        public int[] CollumsWidth
        {
            get
            {
                return _CollumsWidth;
            }
            set
            {
               _CollumsWidth = value;
                
            }
        }

        private string[] _CollumsCapiton;
        [Category("(TIMS) Grid"), Description("Collums Capiton text")]
        public string[] CollumsCapiton
        {
            get
            {
                return _CollumsCapiton;
            }
            set
            {
               _CollumsCapiton = value; 
            }
        }

        private string _SortFN;
        [Category("(TIMS) Grid"), Description("Sort field name")]
        public string SortFN
        {
            get
            {
                return _SortFN;
            }
            set
            {
               _SortFN = value;
            }
        }


        private bool _Ostatus;
        internal bool Ostatus
        {
            get
            {
                return _Ostatus;
            }
            set
            {
                _Ostatus = value;
                
            }
        }
    }
   
}
